/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.dew.discoteca.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import pe.edu.upc.dew.discoteca.utiles.Utiles;

/**
 *
 * @author elvis
 */
@Entity
@Table(name = "lista")
@NamedQueries({@NamedQuery(name = "Lista.findAll", query = "SELECT l FROM Lista l"), @NamedQuery(name = "Lista.findByCodigo", query = "SELECT l FROM Lista l WHERE l.codigo = :codigo"), @NamedQuery(name = "Lista.findByFecha", query = "SELECT l FROM Lista l WHERE l.fecha = :fecha")})
public class Lista implements Serializable {
   private static final long serialVersionUID = 1L;
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Basic(optional = false)
   @Column(name = "codigo")
   private Integer codigo;
   @Basic(optional = false)
   @Column(name = "fecha")
   @Temporal(TemporalType.DATE)
   private Date fecha;
   @OneToMany(cascade = CascadeType.ALL, mappedBy = "codigoLista")
   private List<Contacto> contactoList;
   @JoinColumn(name = "codigoPersona", referencedColumnName = "codigo")
   @ManyToOne(optional = false)
   private Persona codigoPersona;
   @JoinColumn(name = "codigoDiscoteca", referencedColumnName = "codigo")
   @ManyToOne(optional = false)
   private Discoteca codigoDiscoteca;

   public Lista() {
      this.codigoDiscoteca=new Discoteca();
        this.contactoList=new ArrayList<Contacto>();
   }

   public Lista(Integer codigo) {
      this.codigo = codigo;
   }

   public Lista(Integer codigo, Date fecha) {
      this.codigo = codigo;
      this.fecha = fecha;
   }

   public Integer getCodigo() {
      return codigo;
   }

   public void setCodigo(Integer codigo) {
      this.codigo = codigo;
   }

   public Date getFecha() {
      return fecha;
   }

   public void setFecha(Date fecha) {
      this.fecha = fecha;
   }

   public List<Contacto> getContactoList() {
      return contactoList;
   }

   public void setContactoList(List<Contacto> contactoList) {
      this.contactoList = contactoList;
   }

   public Persona getCodigoPersona() {
      return codigoPersona;
   }

   public void setCodigoPersona(Persona codigoPersona) {
      this.codigoPersona = codigoPersona;
   }

   public Discoteca getCodigoDiscoteca() {
      return codigoDiscoteca;
   }

   public void setCodigoDiscoteca(Discoteca codigoDiscoteca) {
      this.codigoDiscoteca = codigoDiscoteca;
   }

   @Override
   public int hashCode() {
      int hash = 0;
      hash += (codigo != null ? codigo.hashCode() : 0);
      return hash;
   }

   @Override
   public boolean equals(Object object) {
      // TODO: Warning - this method won't work in the case the id fields are not set
      if (!(object instanceof Lista)) {
         return false;
      }
      Lista other = (Lista) object;
      if ((this.codigo == null && other.codigo != null) || (this.codigo != null && !this.codigo.equals(other.codigo))) {
         return false;
      }
      return true;
   }

   public String getFecha2(){
        try {
            return Utiles.DateToString(fecha, Utiles.FORMATO_FECHA_CORTA);
        } catch (Exception e) {
        }
        return "";
    }
 

}
